{extend name="public/base" /}
{block name="button"}
<button data-modal='{:url("add")}' data-table-id="MenuTable" class='layui-btn layui-btn-sm layui-btn-primary'>添加菜单</button>
{/block}
{block name="content"}
<div class="layui-tab layui-tab-card">
    <ul class="layui-tab-title">
        <li class="layui-this" onclick="change(0)">全部</li>
        {foreach $top_list as $key=>$v}
        <li  onclick=change("{$v['id']}")>{$v["name"]}</li>
        {/foreach}
    </ul>
</div>
<div class="layui-tab-content">
    <table id="MenuTable" data-url="{:url()}" data-target-search="form.form-search"></table>
</div>

{/block}
{block name='script'}
<script>
    var table
    $(function () {
        table =$('#MenuTable').layTable({
            even: true,
            height: 'full',
            method: 'post',
            url: "{:url('index')}" ,
            page: false,
            cols: [[
                {field: 'id', title: 'id', width: 100, align: 'center'},
                {field: 'sort', title: '排序权重', width: 100, align: 'center'},
                {field: 'icon', title: '图 标', width: 80, align: 'center', templet: '<div><i class="{{d.icon}} font-s18"></i></div>'},
                {field: 'title', title: '菜单名称', minWidth: 220, templet: '<div><span class="color-desc"></span>{{d.title_show}}</div>'},
                {field: 'group', title: '所属分组', minWidth: 200},
                {field: 'url', title: '跳转链接', minWidth: 200},
                {field: 'status', title: '使用状态', minWidth: 120, align: 'center', templet: '#StatusSwitchTpl'},
                {field: 'create_operator', title: '创建人账户', align: 'center', minWidth: 170, sort: true},
                {field: 'update_operator', title: '更新人账户', align: 'center', minWidth: 170, sort: true},
                {toolbar: '#toolbar', title: '操作面板', minWidth: 150, align: 'center', fixed: 'right'},
            ]]
        });
        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : -1};
            $.form.load("{:url('status')}", data, 'post', function (ret) {
                if (ret.code >1) $.msg.error(ret.msg, 3, function () {
                    $('#UserTable').trigger('reload');
                }); else {
                    $('#UserTable').trigger('reload')
                }
                return false;
            }, false);
        });
        $.menu.highlight_subnav("{:url('index')}")
    });
    function change(id) {
        $('#MenuTable').trigger('reload', {where: {pid:id}});
    }
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{-d.status==1?'checked':''}}>
    {{-d.status==1 ? '<b class="color-green">已激活</b>' : '<b class="color-red">已禁用</b>'}}
</script>

<!-- 操控面板的模板 -->
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-sm layui-btn-primary" data-title="添加系统菜单" data-modal='{:url("add")}?pid={{d.id}}'>添 加</a>
    <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="编辑系统菜单" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
</script>
{/block}
